package cn.netjava.blogaction;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.netjava.actioninterface.Action;
import cn.netjava.dao.ArticleDao;
import cn.netjava.dao.ReviewDao;
import cn.netjava.pojo.Article;
import cn.netjava.pojo.Review;

/**
 * this Action use for a user to show an article
 * which is got from the mysql 
 * @author Administrator
 *
 */
public class ShowOneArticleAction implements Action{

	public String excute(HttpServletRequest request,
			HttpServletResponse response) {
		
		ArticleDao adao=ArticleDao.getArticleDao();
		ReviewDao rdao =ReviewDao.getReviewDao();
		
		/*to get the article's ID for getting the article*/
		String articleIDstr = request.getParameter("articleid");
		int articleID =Integer.parseInt(articleIDstr);
		Article article =adao.getOneArticleForArticleID(articleID);
		
		/*put the article to one request object*/		
		request.setAttribute("oneArticle", article);
		
		/*put the article's review to one request object*/
		List<Review> reviewList =rdao.getReviewFromArticleID(articleID);
		request.setAttribute("reviews", reviewList);
   
		return "JSP/personblogjsp/showonearticle.jsp";
	}

}
